Finally Statement

Contains code that will run after a method or function is finished, even if a RuntimeException has occurred.


Syntax

Try

//REALbasic statements

Catch

[ Finally]

//code that executes even if runtime exceptions were raised

End [Try]


Notes

Sometimes a method needs to do some cleanup work whether it is finishing normally or aborting early because of an exception. The optional Finally block at the end of a method or function runs after its exception handlers, if it has any. Code in this block will be executed even if an exception has occured, whether the exception was handled or not. For example, you can write:

Sub SomeFunction()
 //some RB code here...
 Finally
 //some more code that will always execute

See the entries for the Sub and Function statements.


Example

This simple example shows a Finally block that executes even after an exception.

Try
  Raise New RuntimeException()
Finally
 //Executes even though the exception is not handled
MsgBox ("Finally")
End Try

See Also

Catch, Function, Sub statements; Exception, Try blocks.